package com.tianlaiedu.service.impl;

import com.tianlaiedu.bean.Relation;
import com.tianlaiedu.dao.RelationMapper;
import com.tianlaiedu.service.RelationService;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @author:hejing
 * @date:2021/12/1
 */
public class RelationImpl implements RelationService {
    @Override
    public int addRelatin(Relation relation) {
        try(SqlSession sqlSession = com.tianlaiedu.utils.MapperUtil.getSqlSessionFactory().openSession(true)) {
            final RelationMapper relationMapper = sqlSession.getMapper(RelationMapper.class);
            return relationMapper.addRelatin(relation);
        }
    }

    @Override
    public List<Relation> findByLabel(String label) {

        try(SqlSession sqlSession = com.tianlaiedu.utils.MapperUtil.getSqlSessionFactory().openSession(true)) {
            final RelationMapper relationMapper = sqlSession.getMapper(RelationMapper.class);
            return relationMapper.findByLabel(label);
        }
    }

    @Override
    public List<Relation> finByPost(int id) {
        try(SqlSession sqlSession = com.tianlaiedu.utils.MapperUtil.getSqlSessionFactory().openSession(true)) {
            final RelationMapper relationMapper = sqlSession.getMapper(RelationMapper.class);
            return relationMapper.finByPost(id);
        }
    }
}
